{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>物料订单</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="collapse" id="searchBox">
                        <div class="layui-form layui-form-item">
                            <div class="layui-input-inline">
                                <input type="text"  name="start" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})"  class="layui-input layer-date search" placeholder="下单开始日期" />
                            </div>
                            <div class="layui-input-inline">
                                <input type="text"  name="end" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})"  class="layui-input layer-date search" placeholder="下单结束日期" />
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="订单号"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group pull-left" >
                        <a href="javascript:;" onclick="tableReload()" class="btn btn-success" data-toggle="tooltip" title="" data-original-title="刷新表格" data-placement="auto">
                            <i class="fa fa-refresh"></i>
                        </a>
                        <!--<a href="javascript:;" onclick="wk.layer_show('添加管理员','{:url('userAdd')}',900)">-->
                            <!--<button class="btn btn-primary" type="button">-->
                                <!--<i class="fa fa-plus"></i> 添加管理员-->
                            <!--</button>-->
                        <!--</a>-->
                        <!--<button  class="btn btn-danger" href="javascript:;" data-toggle="dropdown">-->
                            <!--<i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>-->
                        <!--</button>-->
                        <!--<ul class="dropdown-menu animated fadeInDown" role="menu">-->
                            <!--<li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-trash-o"></i> 批量删除 </a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="usingAll" id="onAll" data-toggle="tooltip" data-original-title="若未勾选默认启用全部" data-placement="auto"><i class="fa fa-check-circle"></i> 批量启用</a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="forbiddenAll" id="offAll" data-toggle="tooltip" data-original-title="若未勾选默认禁用全部" data-placement="auto"><i class="fa fa-ban"></i> 批量禁用</a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="excelAll" id="excel" data-toggle="tooltip" data-original-title="导出筛选完成数据" data-placement="auto"><i class="fa fa-print"></i> 导出Excel</a></li>-->
                        <!--</ul>-->
                    </div>
                    <div class="input-group pull-right" data-toggle="tooltip" title="" data-original-title="搜索">
                        <button class="btn btn-primary" data-toggle="collapse"
                                data-target="#searchBox" >
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--角色模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.title == null){ }}
                        <span style="color:#ec4758">重新分配角色</span>
                        {{# }else{ }}
                        {{d.title}}
                        {{# } }}
                    </script>
                    <!--支付状态模板-->
                    <script type="text/html" id="staTpl">
                        {{# switch(d.so_status) { case 1: }}
                        未支付
                        {{# break; case 2: }}
                        已支付
                        {{# break; case 3: }}
                        已收货
                        {{# break; } }}
                    </script>
                    <!--订单状态模板-->
                    <script type="text/html" id="dinTpl">
                        {{# switch(d.so_in_out) { case 1: }}
                        正常
                        {{# break; case 2: }}
                        申请退款
                        {{# break; case 3: }}
                        同意
                        {{# break; case 4: }}
                        拒绝
                        {{# break; } }}
                    </script>
                    <!--配送状态模板-->
                    <script type="text/html" id="sendTpl">
                        {{# switch(d.so_send_status) { case 1: }}
                        未配送
                        {{# break; case 2: }}
                        配送中
                        {{# break; case 3: }}
                        配送完成
                        {{# break; } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.so_status == 2 && d.so_in_out == 1 && d.so_send_status == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.so_id}}','{:url('delivery')}','确认订单已配送')" class="btn btn-primary btn-xs m-r-xs" title="去配送"><i class="fa fa-send-o"></i></a>
                        {{# } }}
                        {{# if(d.so_in_out == 2){ }}
                        <a href="javascript:;" onclick="agree('{{d.so_id}}')" class="btn btn-danger btn-xs m-r-xs" title="退款处理"><i class="fa fa-thumb-tack"></i></a>
                        {{# } }}
                        <a href="javascript:;"onclick="wk.layer_show('编辑物流','{:url('wuliuEdit')}?id={{d.so_id}}',900)" class="btn btn-primary btn-xs m-r-xs" title="编辑物流"><i class="fa fa-pencil"></i></a>
                        <a href="javascript:;"onclick="wk.layer_show('订单详情','{:url('orderDetail')}?id={{d.so_id}}')" class="btn btn-primary btn-xs m-r-xs" title="订单详情"><i class="fa fa-eye"></i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Mater/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'so_number', width: 220, title: '订单号', align: 'center'}
                , {field: 's_name', width: '', title: '商户名', align: 'center'}
                , {field: 'so_money', width: '', title: '金额', align: 'center'}
                , {field: 'so_time', width: 180, title: '下单时间',  align: 'center'}
                , {field: 'so_jifen', width: '', title: '积分', align: 'center'}
                , {field: 'so_status', width: '', title: '支付状态', align: 'center',templet:'#staTpl'}
                , {field: 'so_in_out', width: '', title: '订单状态', align: 'center',templet:'#dinTpl'}
                , {field: 'so_send_status', width: '', title: '订单状态', align: 'center',templet:'#sendTpl'}
                , {field: 'so_wuliu_name', width: '', title: '物流公司', align: 'center'}
                , {field: 'so_wuliu_num', width: '', title: '单号', align: 'center'}
                , {field: 's_address', width: '', title: '地址', align: 'center'}
                , {field: 's_phone', width: '', title: '手机号', align: 'center'}
                , {fixed: 'right', width: 180, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
    });
    function agree(id){
        layer.confirm('退款同意吗？', {
            btn: ['同意','拒绝'] //按钮
        }, function(){
            change(3,id)
        }, function(){
            change(4,id)
        });
    }

    function change(num,id){
        $.ajax({
            url:"{:url('agreetui')}",
            type:'post',
            data:'num='+num+'&id='+id,
            dataType:'json',
            success:function(res){
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    })
                }else if(res.code == 100){
                    wk.error(res.msg,'',2);
                }
            }
        })
    }
</script>
</body>
</html>